
package com.yisu.auction.manager.core.service.impl.func;

import com.google.common.collect.Lists;

import java.util.List;


/**
 * author: 赵杰
 * Business Description：商品幸运号公用方法
 * createTime：2017/8/10
 */

public class LuckyNumberUtil {

    /**
     * 通过商品ID此编号及总价格创建幸运号
     *
     * @param goodsId 商品ID
     * @param price   商品价格
     * @param term    期号
     * @return
     */

    public static boolean createLuckyNumberByGoodsId(long goodsId, Integer price, Integer term) {
        List<Long> luckyNumbers = Lists.newArrayList();
        try {
            String luckyNumberKey = "luckyNumber_"+goodsId + "_" + term;
            if (RedisClusterClient.existsKey(luckyNumberKey)) {
                return false;
            }
            for (int i = 0; i < price; i++) {
                luckyNumbers.add(generateLuckyNumber(i));
            }
            RedisClusterClient.put(luckyNumberKey, luckyNumbers);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


    /**
     * @param count
     * @return
     * @throws
     * @Title: generateLuckyNumber
     * @Description: 生成幸运号
     */

    public static Long generateLuckyNumber(Integer count) {
        Long result = 10000001l;
        result += count;
        return result;
    }
}

